﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BLL.Procurement
{
    public class T_PUB_PURCHASE
    {
        private readonly DALL.Procurement.T_PUB_PURCHASE dal=new DALL.Procurement.T_PUB_PURCHASE();
		public T_PUB_PURCHASE()
		{}

        /// <summary>
        /// 获取采购主题智能提示
        /// </summary>
        /// <param name="branch_id"></param>
        /// <returns></returns>
        public DataSet GetPurchaseApplyTitel(int branch_id)
        {
            return dal.GetPurchaseApplyTitel(branch_id);
        }

        public DataSet GetPurchaseApplyTitel()
        {
            return dal.GetPurchaseApplyTitel();
        }

		#region  Method
        /// <summary>
        /// 根据条件获得数据列表
        /// </summary>
        /// <param name="title">申请标题</param>
        /// <param name="state">申请状态</param>
        /// <param name="begintime">申请时间</param>
        /// <param name="endtime">截止时间</param>
        /// <returns></returns>
        public DataSet GetApplyList(string title, string state, DateTime begintime, DateTime endtime)
        {
            string strWhere = "";
            if (!string.IsNullOrEmpty(title))
            {
                strWhere += string.Format(" and TITLE like '%{0}%'", title);
            }
            if (state != "0")
            {
                strWhere += string.Format(" and STATE='{0}'", state);
            }
            if (!string.IsNullOrEmpty(begintime.ToString()))
            {
                strWhere += string.Format(" and APPLICANT_TIME >= '{0}' ", begintime);
            }
            if (!string.IsNullOrEmpty(endtime.ToString()))
            {
                strWhere += string.Format(" and APPLICANT_TIME <= '{0}' ", endtime);
            }
            DataSet ds = dal.GetApplyList(strWhere);
            return ds;
        }
        /// <summary>
        /// 根据条件查找采购信息
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="state">状态</param>
        /// <param name="branchid">分店编号</param>
        /// <param name="begintime">开始时间</param>
        /// <param name="endtime">截止时间</param>
        /// <returns></returns>
        public DataSet GetApplyList(string title, string state, string branchid, DateTime begintime, DateTime endtime)
        {
            string strWhere = "";
            if (!string.IsNullOrEmpty(title))
            {
                strWhere += string.Format(" and TITLE like '%{0}%'", title);
            }
            if (state != "0")
            {
                strWhere += string.Format(" and STATE in({0})", state);
            }
            if (!string.IsNullOrEmpty(branchid))
            {
                strWhere += string.Format(" and a.BRANCH_ID='{0}'", branchid);
            }
            if (!string.IsNullOrEmpty(begintime.ToString()))
            {
                strWhere += string.Format(" and APPLICANT_TIME >= '{0}' ", begintime);
            }
            if (!string.IsNullOrEmpty(endtime.ToString()))
            {
                strWhere += string.Format(" and APPLICANT_TIME <= '{0}' ", endtime);
            }
            DataSet ds = dal.GetApplyList(strWhere);
            return ds;
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.Procurement.T_PUB_PURCHASE model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Procurement.T_PUB_PURCHASE model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            return dal.Delete(ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Procurement.T_PUB_PURCHASE GetModel(string ID)
        {

            return dal.GetModel(ID);
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Model.Procurement.T_PUB_PURCHASE> GetModelList(string strWhere)
		{
            return dal.GetListArray(strWhere);
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
		#endregion  Method
    }
}
